//
//  ViewController.m
//  IOSDemo
//
//  Created by Dishan Fernando on 12/12/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "ViewController.h"

@implementation ViewController
@synthesize value1TxtField;
@synthesize value2TxtField;
@synthesize resultLbl;

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    [self setValue1TxtField:nil];
    [self setValue2TxtField:nil];
    [self setResultLbl:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
	[super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
	[super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}


-(void) hideKeyboard {
    [value1TxtField resignFirstResponder];
    [value2TxtField resignFirstResponder];
}

- (IBAction)plueBtnClicked:(id)sender {
    int value1 = [value1TxtField.text intValue];
    int value2 = [value2TxtField.text intValue];
    int sum = value1+value2;
    resultLbl.text = [NSString stringWithFormat:@"%d", sum];
    [self hideKeyboard];
}

- (IBAction)minusBtnClicked:(id)sender {
    int value1 = [value1TxtField.text intValue];
    int value2 = [value2TxtField.text intValue];
    int minus = value1-value2;
    resultLbl.text = [NSString stringWithFormat:@"%d", minus];
    [self hideKeyboard];
}

- (IBAction)multiplyBtnClicked:(id)sender {
    int value1 = [value1TxtField.text intValue];
    int value2 = [value2TxtField.text intValue];
    int multi = value1*value2;
    resultLbl.text = [NSString stringWithFormat:@"%d", multi];
    [self hideKeyboard];
}

- (IBAction)divideBtnClicked:(id)sender {
    int value1 = [value1TxtField.text intValue];
    int value2 = [value2TxtField.text intValue];
    if(value2 != 0) {
        int div = value1/value2;
        resultLbl.text = [NSString stringWithFormat:@"%d", div];
    }else {
        resultLbl.text = @"Error! divide by zero";
    }
    [self hideKeyboard];
}


@end
